package com.mucong.easytodo.ui.component;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.mucong.easytodo.constant.ColorTheme;
import com.mucong.easytodo.ui.MainFrame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

@Component
public class TitlePane extends JPanel {
    private JLabel close;
    private JLabel logo;
    public JPanel logopane;
    public JPanel closepane;

    @Autowired
    private MainFrame mainFrame;

    public TitlePane() {
        final JPanel panel1 = this;
        panel1.setBackground(ColorTheme.BLUE);
        panel1.setLayout(new GridBagLayout());
        panel1.setAutoscrolls(false);

        logopane = new JPanel();
        logopane.setBackground(ColorTheme.BLUE);
        logopane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0.5;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel1.add(logopane, gbc);
//        logo = new JLabel();
//        ImageIcon logoIcon = new ImageIcon(getClass().getResource("/icon/logo128.png"));
//        logoIcon = new ImageIcon(logoIcon.getImage().getScaledInstance(32, 32, Image.SCALE_DEFAULT));
//        logo.setIcon(logoIcon);
//        logo.setPreferredSize(new Dimension(32, 32));
//        logo.setText("");
//        logopane.add(logo);
        JLabel logotitle = new JLabel("EasyTodo");
        logotitle.setFont(new Font(logotitle.getFont().getFontName(), 0, 20));
        logotitle.setForeground(Color.white);
        logopane.add(logotitle);


        closepane = new JPanel();
        closepane.setBackground(ColorTheme.BLUE);
        closepane.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));

        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.weightx = 0.5;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel1.add(closepane, gbc);
        close = new JLabel();
        ImageIcon closeIcon = new ImageIcon(getClass().getResource("/icon/Close.png"));
        closeIcon = new ImageIcon(closeIcon.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT));
        close.setIcon(closeIcon);
        close.setText("");
        close.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                mainFrame.setVisible(false);
            }
        });
        closepane.add(close);

    }


    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridBagLayout());
        panel1.setAlignmentX(0.0f);
        panel1.setAlignmentY(0.0f);
        panel1.setAutoscrolls(false);
        closepane = new JPanel();
        closepane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0.5;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel1.add(closepane, gbc);
        close = new JLabel();
        close.setIcon(new ImageIcon(getClass().getResource("/icon/Close.png")));
        close.setText("");
        closepane.add(close);
        logopane = new JPanel();
        logopane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 0.1;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        panel1.add(logopane, gbc);
        logo = new JLabel();
        logo.setIcon(new ImageIcon(getClass().getResource("/icon/logo128.png")));
        logo.setMaximumSize(new Dimension(16, 16));
        logo.setMinimumSize(new Dimension(16, 16));
        logo.setText("");
        logopane.add(logo);
    }
}
